package net.yunxinyong.cec.controller;

import net.yunxinyong.cec.service.InventoryManagerService;
import net.yunxinyong.cec.utils.CECResult;
import net.yunxinyong.cec.utils.PageBean;
import net.yunxinyong.cec.vo.InventoryManagerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @author 李跃
 * @date 18/9/20
 */
@RequestMapping(value = "inventory")
@RestController
public class InventoryManagerController {

    @Autowired
    private InventoryManagerService inventoryManagerService;

    @GetMapping(value = "getEnterpriseInfo/{street}/{page}/{rows}")
    public CECResult getEnterpriseByName(@RequestParam String name, @PathVariable String street,@PathVariable int page,@PathVariable int rows){
        PageBean pageBean = inventoryManagerService.listEnterpriseByName(name, street, page, rows);
        Map<String, Integer> map = inventoryManagerService.getNumberOfInventoryStatus(street);

        InventoryManagerVo inventoryManagerVo = new InventoryManagerVo();
        //把pageBean数据放入对象中去
        inventoryManagerVo.setTotal(pageBean.getTotal());
        inventoryManagerVo.setTotalPages(pageBean.getTotalPages());
        inventoryManagerVo.setPageDatas(pageBean.getPageDatas());
        //把该街道内企业清查数量的信息放入对象中去
        inventoryManagerVo.setTotalEnterprise(map.get("totalEnterprise"));
        inventoryManagerVo.setInventoryEnterprise(map.get("inventoryEnterprise"));
        inventoryManagerVo.setUnInventoryEnterprise(map.get("unInventoryEnterprise"));

        if(inventoryManagerVo.getPageDatas().isEmpty()){
            return CECResult.build(500,"没有查询到企业信息",inventoryManagerVo);
        }
        return CECResult.build(200,"查询到了企业信息",inventoryManagerVo);
    }


    @GetMapping(value = "getStatsNum/{street}")
    public CECResult getEnterpriseStatusNum(@PathVariable String street){
        Map<String, Integer> map = inventoryManagerService.getNumberOfInventoryStatus(street);
        if(map.isEmpty()){
            return CECResult.build(500,"没有查询到企业清查状态的数量信息",map);
        }
        return CECResult.build(200,"查询到了企业清查状态数量的信息",map);
    }



}
